 
import MySQLdb,xlwt,sys

def out_excel():
    #导出工单到Excel表格
    db = MySQLdb.connect("47.93.53.27","root","741852aa","ping_test_db",charset="utf8")    
    cursor = db.cursor()
    cursor.execute('select * from ping_test_app_web_db')
    db_data=cursor.fetchall()
    #for i in db_data:
        #print(i)
    fields = cursor.description
    workbook = xlwt.Workbook()
    sheet = workbook.add_sheet('name',cell_overwrite_ok=True)
    #for field in range(1,len(fields)):
        #sheet.write(0,field,fields[field][0])
    sheet.write(0,1,'从第三行开始导入')
    print(fields)
    print(db_data)
    # 获取并写入数据段信息
    row = 1
    col = 1
    for row in range(1,len(db_data)+1):
        for col in range(1,len(fields)):
            sheet.write(row+1,col-1,u'%s'%db_data[row-1][col])

    workbook.save(r'./z_dist/readout.xls')


